<?php
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_djhome/model')->方法名();
*/
namespace jy_djhome;
defined('BY_JYA') or exit('error');
class model extends \plugin{
	public function chefee($chetype=1,$kaddress=array(),$wlatlng=array()){
		if(!$kaddress['lat_lng']){
			$data = cfc('tools')->getgeocode($kaddress);
			if($data['status'] == 1 && 0 < $data['count']) {
				$location = explode(',', $data['geocodes'][0]['location']);
				$kaddress['lat_lng']=array('lat'=>$location[1],'lng'=>$location[0]);
			}
		}
		if($kaddress['lat_lng'] && $wlatlng['lng'] && $wlatlng['lng']){
			$distance = cfc('tools')->getdistance($kaddress['lat_lng']['lat'], $kaddress['lat_lng']['lng'], $wlatlng['lat'], $wlatlng['lng']);
		}else{
			$distance = 0;
		}
		$juli=$distance>0?$distance/1000:0;
		if($chetype==2){
				if ($juli <= $this->setting['start_km']) {
					$chefee = round($this->setting['start_fee'], 2);
				}elseif ($this->setting['start_km'] < $juli && $juli <= $this->setting['start_km']+ $this->setting['pre_km']) {
					$km = $juli - intval($this->setting['start_km']);
					$chefee = round($this->setting['start_fee'] + $this->setting['pre_km_fee'] * $km, 2);
				}else {
					$chefee = $this->setting['fixed_fee']?round($this->setting['fixed_fee'], 2):round($this->setting['start_fee']*3, 2);
				}
		}elseif($chetype==1){
				if ($juli <= $this->setting['start_km1']) {
					$chefee = round($this->setting['start_fee1'], 2);
				}elseif ($this->setting['start_km1'] < $juli && $juli <= $this->setting['start_km1']+ $this->setting['pre_km1']) {
					$km = $juli - intval($this->setting['start_km1']);
					$chefee = round($this->setting['start_fee1'] + $this->setting['pre_km_fee1'] * $km, 2);
				}else {
					$chefee = $this->setting['fixed_fee1']?round($this->setting['fixed_fee1'], 2):round($this->setting['start_fee1']*3, 2);
				}
		}
		return array('juli'=>$juli,'chefee'=>$chefee);
	}
}
?>